﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class admin_func_Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            ctpDataContext db = new ctpDataContext();

            var data = from p in db.ct_profiles
                       select p.title;
            
            this.DropDownList1.DataSource = data;
            this.DropDownList1.DataBind();
 

        }
    }

    private string district(string conti)
    {
        switch (int.Parse(conti))
        {
            case 0:
                return "未設定";
            case 1:
                return "美洲";
            case 2:
                return "亞洲";
            case 3:
                return "歐洲";
            case 4:
                return "大洋洲";
        }
        return "0";
    }
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        ctpDataContext db = new ctpDataContext();

        this.Label1.Text = district(db.ct_profiles.Single(p => p.title == this.DropDownList1.SelectedValue).continent.ToString());
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        ctpDataContext db = new ctpDataContext();
        
        ct_profile ct = db.ct_profiles.Single(p => p.title == this.DropDownList1.SelectedValue);
        ct.continent = DataUtil.StringToInt(this.DropDownList2.SelectedValue);
        db.SubmitChanges();
        
        this.Label1.Text = district(this.DropDownList2.SelectedValue.ToString());
    }
}
